<?php
class CommentsController extends MyAdminController
{
	const PAGE_SIZE = 50;
	public function actionIndex()
	{
		$page = intval(Yii::app()->request->getParam('pageNum')) - 1;
		
		// 查库
		$CDbCriteria = new CDbCriteria;
		$CDbCriteria->order = "create_time DESC";
		
		// 分页
		$count = Guest_comments::model()->count();
		$pages = new CPagination($count);
		$pages->pageSize = self::PAGE_SIZE;
		$pages->currentPage = $page;
		$pages->applyLimit($CDbCriteria);
		
		$rows = Guest_comments::model()->findAll($CDbCriteria);
		
		// 显示
		$data = array();
		$data['rows'] = $rows;
		$data['pages'] = $pages;
		$this->display('index', $data);
	}
	
	public function actionDelete()
	{
		$id = Yii::app()->request->getParam('id');
		if($id)
		{
			if($comments = Guest_comments::model()->findByPk($id))
			{
				$comments->delete();
				$this->alert_ok('删除成功');
			}
		}
		$this->alert_error('无此留言');
	}
	
	public function actionView()
	{
		$id = Yii::app()->request->getParam('id');
		if($id)
		{
			if($comments = Guest_comments::model()->findByPk($id))
			{
				echo CHtml::encode($comments->content);
			}
		}
	}
}